package com.bridgeintelligent.tag.engine.es.base;

import com.bridgeintelligent.tag.engine.es.model.CustomerGroupModel;
import com.bridgeintelligent.tag.engine.es.model.DataSetModel;
import com.bridgeintelligent.tag.engine.es.model.IndexModel;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.search.SearchHit;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by JackCheung on 2019/9/24 5:14 PM.
 */
public interface IEngineESHelper {
    RestHighLevelClient getClient();
    /**
     * 创建索引字段映射
     *
     * @param indexName indexName
     */
    void updateIndexMapping(String indexName);

    /**
     * 获取索引下的mapping字段集合
     * @param indexName
     * @return
     */
    Set<String> getIndexMapping(String indexName);

    /**
     * 批量插入
     *
     * @param indexName indexName
     * @param map map
     */
    void bulkInsert(String indexName, Map<String, Map<String, Object>> map);

    /**
     * 批量更新
     *
     * @param indexName indexName
     * @param map map
     */
    void bulkUpdate(String indexName, Map<String, Map<String, Object>> map);

    /**
     * es查询
     *
     * @param indexName indexName
     * @param dataSetModel dataSetModel
     * @return SearchResponse
     */
    SearchResponse dataSetSearch(String indexName, DataSetModel dataSetModel);

    /**
     * 查询
     *
     * @param indexName indexName
     * @return SearchResponse
     */
    SearchResponse querySearch(String indexName);

    /**
     * 客群分析
     *
     * @param indexName indexName
     * @param customerGroupModel customerGroupModel
     * @return SearchResponse
     */
    SearchResponse customerGroup(String indexName, CustomerGroupModel customerGroupModel);

    /**
     * 聚合分析
     *
     * @param indexModel indexModel
     * @param indexName indexName
     * @return List<SearchResponse>
     */
    List<SearchResponse> indexSearch(IndexModel indexModel, String... indexName);


    /**
     * scroll查询
     *
     * @param indexName indexName
     * @param boolQueryBuilder boolQueryBuilder
     * @param fieldsSet fieldsSet
     * @return SearchResponse
     */
    List<SearchHit[]> scrollSearch(String indexName, BoolQueryBuilder boolQueryBuilder,Set<String> fieldsSet);
}